package com.fenghongzhang.module_user.login

import com.fenghongzhang.lib_base.core.BaseRepository
import com.fenghongzhang.module_user.api.UserApiService
import javax.inject.Inject


class LoginRepository @Inject constructor()  : BaseRepository() {

    //11, 注入网络请求接口
    @Inject
    lateinit var userApiService: UserApiService


    //9, 发送真是的网络请求
    suspend fun login(username: String, password: String): Result<LoginState> {
        //10, 调用网络请求Retrofit+okhttp
        val userInfo = userApiService.getUserInfo(username,password)
        return if (userInfo.code == 200) {
            // 16, 返回数据
            Result.success(LoginState( userInfo = userInfo.data , isSucess = true))
        } else {
            Result.failure(IllegalArgumentException("用户名或密码错误"))
        }

    }
}